﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sim3D_practicum.Physics
{
    public struct Row
    {
        public double A { get; set; }
        public double B { get; set; }
        public double C { get; set; }
    };

    public class Matrix3D
    {
        #region Matrix using the Column struct
        public Matrix3D( Row leftRow, Row middleRow, Row rightRow )
        {
            A1 = leftRow.A;
            A2 = leftRow.B;
            A3 = leftRow.C;

            B1 = middleRow.A;
            B2 = middleRow.B;
            B3 = middleRow.C;

            C1 = rightRow.A;
            C2 = rightRow.B;
            C3 = rightRow.C;
        }
        #endregion
        #region Matrix using individual values
        public double A1 { get; set; }
        public double A2 { get; set; }
        public double A3 { get; set; }

        public double B1 { get; set; }
        public double B2 { get; set; }
        public double B3 { get; set; }

        public double C1 { get; set; }
        public double C2 { get; set; }
        public double C3 { get; set; }

        /// <summary>
        /// A matrix which has all values individually set
        /// </summary>
        /// <param name="a1">the value in row 1, column 1 of the matrix</param>
        /// <param name="a2">the value in row 2, column 1 of the matrix</param>
        /// <param name="a3">the value in row 3, column 1 of the matrix</param>
        /// <param name="b1">the value in row 1, column 2 of the matrix</param>
        /// <param name="b2">the value in row 2, column 2 of the matrix</param>
        /// <param name="b3">the value in row 3, column 2 of the matrix</param>
        /// <param name="c1">the value in row 1, column 3 of the matrix</param>
        /// <param name="c2">the value in row 2, column 3 of the matrix</param>
        /// <param name="c3">the value in row 3, column 3 of the matrix</param>
        public Matrix3D( double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3 )
        {
            A1 = a1;
            A2 = a2;
            A3 = a3;

            B1 = b1;
            B2 = b2;
            B3 = b3;

            C1 = c1;
            C2 = c2;
            C3 = c3;
        }
        /// <summary>
        /// This matrix has all it's values set to 0.0
        /// </summary>
        public Matrix3D( )
        {
            
        }
        #endregion
        
        /// <summary>
        /// Creates and returns a Unity matrix, of which the diagonal values ( A1, B2, C3 ) are 1, and the rest is all 0.
        /// </summary>
        public Matrix3D UnityMatrix
        {
            get 
            { 
                return new Matrix3D 
                { 
                    A1 = 1.0,
                    B2 = 1.0,
                    C3 = 1.0
                }; 
            }
        }

        /// <summary>
        /// Gets the determinant of this matrix
        /// </summary>
        public double Determinant
        {
            get 
            { 
                return    
                    A1 * ( B2 * C3 - C2 * B3 ) -
                    A2 * ( B1 * C3 - C1 * B3 ) +
                    A3 * ( B1 * C2 - C1 * B2 ); 
            }
        }       
    }
}